﻿	
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Conference.Core.SL;
using Conference.Core.Sal.DataContracts;
using Conference.Core.Sal.DataRequests;
using Conference.Core.Sal.DataResponses;
using TeaLightV5.Foundation.Sal.DataRequests;

namespace Conference.Core.BL.Sync
{
    public class SyncSpeaker : SyncObject<Conference.Core.Sal.DataContracts.SpeakerDataContract, Conference.Core.BL.Entities.SpeakerEntity>
    { 
        public SyncSpeaker() 
            : base("Speakers")
        {
        }

        protected override Conference.Core.Sal.DataContracts.SpeakerDataContract FromDatabase(Conference.Core.BL.Entities.SpeakerEntity item)
        {
            return new Conference.Core.Sal.DataContracts.SpeakerDataContract()
                {
					Id = new Guid(item.Id),
					Created = item.Created,		
					CreatedBy = item.CreatedBy,		
					Modified = item.Modified,		
					ModifiedBy = item.ModifiedBy,		
					Name = item.Name,		
					Title = item.Title,		
					Company = item.Company,		
					Biography = item.Biography,		
	                };
        }

        protected override Conference.Core.BL.Entities.SpeakerEntity FromService(Conference.Core.Sal.DataContracts.SpeakerDataContract item)
        {
            return new Conference.Core.BL.Entities.SpeakerEntity()
            {
                
					Id = item.Id.ToString("N"),		
					Created = item.Created,		
					CreatedBy = item.CreatedBy,		
					Modified = item.Modified,		
					ModifiedBy = item.ModifiedBy,		
					Name = item.Name,		
					Title = item.Title,		
					Company = item.Company,		
					Biography = item.Biography,		
		
			};
		}

		protected override Collection<SpeakerDataContract> UpdateFromServiceEntity(SynchronizeServiceClient service, DateTime fromDate)
		{
		    IAsyncResult a = service.BeginGetSpeakersByModifiedDate(new GetByModifiedDateRequest(), null, null);
		    SpeakerDataResponse l = service.EndGetSpeakersByModifiedDate(a);
		    if (l.IsError)
		    {
                return null;
		    }
            return l.Data;
        }

        protected override void UpdateFromServiceDeleted(SynchronizeServiceClient service, DateTime fromDate)
        {
            
        }

        protected override void UpdateFromDatabaseEntity(SynchronizeServiceClient data, Collection<Conference.Core.Sal.DataContracts.SpeakerDataContract> list)
        {
            
        }

        protected override void UpdateFromDatabaseDeleted(SynchronizeServiceClient data, DeletedRowRequest request)
        {
            
        }

	}
}

